<template>
    <div>
        <!-- 展示查询数据 -->
        <el-table :data="ObdList" style="width: 100%">
            <el-table-column prop="obdId" label="入库申请编号" ></el-table-column>
            <el-table-column prop="obdTime" label="入库时间" ></el-table-column>
            <el-table-column label="仓库对接人" prop="userName">
                <template v-slot="scope">
                    <el-select v-model="scope.row.userId" placeholder="仓库对接人">
                        <el-option
                                v-for="inventoryTaker in inventoryTakers"
                                :key="inventoryTaker.id"
                                :label="inventoryTaker.name"
                                :value="inventoryTaker.id">
                        </el-option>
                    </el-select>
                </template>
            </el-table-column>
            <el-table-column prop="statusStr" label="状态" ></el-table-column>
            <el-table-column label="操作">
                <template v-slot="scope">
                    <el-button type="text" @click="handleDetail(scope.row)">查看详情</el-button>
                    <el-button type="text" @click="updateObdStatus(scope.row)">指定员工</el-button>
                </template>
            </el-table-column>
        </el-table>
        <!-- 查看详情的对话框 -->
        <el-dialog title="商品详情" v-model="dialogVisible">
            <el-table :data="detailList">
                <el-table-column prop="brand" label="商品品牌"></el-table-column>
                <el-table-column prop="productName" label="商品名称"></el-table-column>
                <el-table-column prop="typeName" label="包装类型"></el-table-column>
                <el-table-column prop="weight" label="体积/重量"></el-table-column>
                <el-table-column prop="price" label="进货价"></el-table-column>
                <el-table-column prop="total" label="数量"></el-table-column>
            </el-table>
            <template #footer>
        <span class="dialog-footer">
          <el-button @click="dialogVisible = false">关闭</el-button>
        </span>
            </template>
        </el-dialog>
    </div>
</template>

<script setup>
    import {onMounted, reactive, ref} from 'vue'
    import {selectObd,updateObd} from "@/api/sale/obdDelivery";
    import {getOrdinaryEmployees} from  '@/api/warehouse/invInventory'
    const detailList = ref([]) // 报价单商品详情数据
    const dialogVisible = ref(false) // 控制详情对话框的显示
    const ObdList=ref([])
    const time=ref('')
    const inventoryTakers = ref([]);
    const conditions = ref({
        id:0,
        takerId:'',
    });
    const params = ref();
    function fetchInventoryTakers() {
        getOrdinaryEmployees().then(response => {
            inventoryTakers.value = response.allOrdinaryEmployees.map(inventoryTaker => ({
                id: inventoryTaker.userId,
                name: inventoryTaker.userName,
            }));
        }).catch(error => {
            console.error('获取负责人列表失败:', error);
            // 错误处理逻辑
        });
    }


    handleSearch();
    function handleSearch(){
        selectObd().then(res=>{
            console.log(res)
            ObdList.value=res.obdDeliveryVoList;
            ObdList.value.forEach(item=>{
                item.obdTime=formatDate(new Date(item.obdTime));
            })
            console.log("ObdList:"+ObdList.value)
        })

    }
    const formatDate = (date) => {
        const year = date.getFullYear();
        const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始，所以加1
        const day = String(date.getDate()).padStart(2, '0');
        return `${year}-${month}-${day}`;
    };

    // 查看详情
    const handleDetail = (row) => {
        console.log("row:"+row)
        detailList.value = [];
        row.saleOrderItemList.forEach(item=>{
            detailList.value.push(item)
        })
        dialogVisible.value = true
    }
    onMounted(() => {
        // 初始化逻辑
        fetchInventoryTakers()
    });



</script>

<style scoped>
    /* 可以在这里添加一些样式 */
</style>
